<?php

class OrderController extends Common {

    public function __construct() {
        parent::__construct();
        $this->load->model('order');
    }

    /**
     * 订单列表
     */
    public function listAction() {
        $page     = $this->get('page') ? $this->get('page') : 1;
        $pagesize = 10;
        $pagelist = $this->instance('pagelist');
        $pagelist->loadconfig();
        $where = '';
        $model = $this->model('order');
        $total = $model->count('order', 'id', $where);
        $urlparam = array(
            'page' => '{page}',
        );
        $data = $model->page_limit($page, $pagesize)->order(array('id DESC'))->select();
        $pagelist = $pagelist->total($total)->url(url('admin/order/list', $urlparam))->num($pagesize)->page($page)->output();
        $this->view->assign(array(
            'page' => $page,
            'data' => $data,
            'pagelist'=> $pagelist,
        )); //assign()对视图变量完成赋值
        $this->view->display('/admin/order/order_list');  //这里是对视图文件的加载
    }

    public function orderInfoAction()
    {
        $id = $this->get('id')?:0;
        if(empty($id)){echo '订单有误';}
        $model = $this->model('order');
        $data = $model->getOne('id='.$id);  //订单详细信息
//        $goods = $goodsModel->getAll('order_id='.$id);  //订单中所有商品
        $sql = "SELECT og.goods_id,og.price,og.num,og.create_time,cg.name,cg.banner FROM `ca_order_goods` as og LEFT JOIN ca_order as o on og.order_id=o.id
LEFT JOIN ca_content_1_goods as cg on og.goods_id=cg.id where o.id='".$id."'";
        $goods = $model->execute($sql);
        $this->view->assign(array(
            'data' => $data,
            'goods' => $goods,
        )); //assign()对视图变量完成赋值
        $this->view->display('/admin/order/order_info');  //这里是对视图文件的加载
    }

    public function sfAction(){
        $username=$_POST[username];   //获取视图文件传过来的表单的值  表单我用post传值
        // $model = $this->model('member');  //实例化model 这里的两行是用fine的原有的写的，但是我感觉这样不灵活我下面又用php的写了因为我感觉还是php写的顺手，大家自己感觉什么好就用什么吧
        // $data = $model->getAll('username=?', "$username"); //用的fine的getall函数
        $sql="select * from fn_member where username='$username' ";   //sql语句  这里是php的
        $row=mysql_query($sql);  //php执行sql
        $data=mysql_fetch_assoc($row);  //获取sql语句得到的值
        $this->view->assign('data',$data); //assign()对视图变量完成赋值
        $this->view->display('sf'); //加载视图文件
    }

}
